<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 3.4</title>
</head>

<body>
<?php
	function tim_hoa($tenhoa,$manghoa)
	{
		$n=count($manghoa);
		$kq=0;
		for($i=0;$i<$n;$i++)
		{
			if(strcasecmp($tenhoa,$manghoa[$i])==0)
				$kq=1;
		}
		return $kq;
	}
	if(isset($_POST['hoa']))
	{
		$hoa=	$_POST['hoa'];
		$mang=explode("--",trim($_POST['giohoa']));
		$n=count($mang);
		if(tim_hoa($hoa,$mang)==1)
		{
			$kq="Hoa <b>$hoa</b> đã tồn tại trong giỏ hoa";
		}
		else
			$mang[$n]=$hoa;
		$giohoa=implode("--",$mang);
	}
?>
<form id="form1" name="form1" method="post" action="Bai3_4.php">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#FFCC00" style="text-align: center; font-size: 24px; color: #F00; font-weight: bold; font-style: italic;">
      <td colspan="3">MUA HOA</td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#FF6666" style="color: #C00; font-weight: bold;">Loại hoa bạn chọn:</td>
      <td nowrap="nowrap" bgcolor="#FF6666"><input name="hoa" type="text" id="hoa" value="<?php echo $_POST['hoa'];?>" /></td>
      <td nowrap="nowrap" bgcolor="#FF6666"><input type="submit" name="submit" id="submit" value="Thêm vào giỏ hoa" /></td>
    </tr>
    <tr>
      <td colspan="2" nowrap="nowrap" bgcolor="#FF6666" style="color: #C00; font-weight: bold;">Giỏ hoa của bạn có:</td>
      <td nowrap="nowrap" bgcolor="#FF6666" style="text-align: right"><?php echo $kq;?></td>
    </tr>
    <tr style="text-align: center">
      <td colspan="3" nowrap="nowrap" bgcolor="#FF6666"><textarea name="giohoa" id="giohoa" cols="98%" rows="5"><?php echo $giohoa;?></textarea></td>
    </tr>
  </table>
</form>
</body>
</html>